<?php
header("Pragma: no-cache");
header("Cache: no-cache");
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");

try {
	require_once "lib/autoload.php";
	session_start();

	if (!isset($_REQUEST["action"])) {
		throw new Exception("Action não definido!");
	}
		
	$dest = explode(".", $_REQUEST["action"]);
	$dest[0] .= "bsn";
	
	if (!isset($_SESSION["usuario"]) && !($dest[0] == 'usuariobsn' && $dest[1] == 'login' || $dest[1] == 'redefinirSenha')) {    
		$dest[0] = "usuariobsn";
		$dest[1] = "logout";
	}
	
	$obj = new $dest[0];
	$obj->$dest[1]($_REQUEST);
	echo $obj->toJSON();
} catch (Exception $e) {
	$res['Result'] = "ERROR";
	$res['Message'] = $e->getMessage();
	echo json_encode($res);
}
?> 
